package com.credithc.signature.job.controller;

import com.credithc.baseserv.core.codes.CoreCodes;
import com.credithc.baseserv.core.message.Message;
import com.credithc.baseserv.core.message.MessageFactory;
import com.credithc.signature.common.ro.facade.ReSignData;
import com.credithc.signature.job.ro.JobRequest;
import com.credithc.signature.job.service.SignatureService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @desc: <br/>
 * @author: Jingbo Hu<br/>
 * @time：2021年06⽉30⽇<br/>
 * @version：v1.0.0<br>
 */
@Slf4j
@RestController
@RequestMapping("/api/job/v1")
public class JobController {

    @Autowired
    MessageFactory messageFactory;

    @Autowired
    SignatureService signatureService;

    /**
     * 签章重签方法
     *
     * @param reSignData
     * @return
     */
    @ResponseBody
    @PostMapping("/resign")
    public Message resign(@RequestBody ReSignData reSignData) {
        JobRequest jobRequest = new JobRequest();
        BeanUtils.copyProperties(reSignData, jobRequest);
        jobRequest.setCallbackUrl(reSignData.getCallBackUrl());
        jobRequest.setJsonBody(reSignData.getRequestData());
        signatureService.process(jobRequest);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, "调用重试方法成功");
    }
}
